package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.annotation.RequireLogain;
import cn.wolfcode.wolf2w.domain.*;
import cn.wolfcode.wolf2w.service.IDestinationService;
import cn.wolfcode.wolf2w.service.IStrategyCatalogService;
import cn.wolfcode.wolf2w.service.IStrategyService;
import cn.wolfcode.wolf2w.service.ITravelService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("destinations")
public class DestinationsController {

    @Autowired
    private IDestinationService destinationService;
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;

    @GetMapping("/hotRegion")
    public Object hotRegion() {
        //查询出所有热门区域
        List<Region> list = destinationService.selectHotRegion();
        JsonResult success = JsonResult.success();
        success.setData(list);
        return success;
    }
    @GetMapping("/search")
    public Object search(String regionId) {
        List<Destination> list;
        //根据热门区域id,查出其下所有子目的地
        list = destinationService.selectDestsByReginoIdQ(regionId);
        JsonResult success = JsonResult.success();
        success.setData(list);
        return success;
    }
    @GetMapping("/toasts")
    public Object toasts(String destId) {
        //查询此目的地id的吐司
        List<Destination> toasts = destinationService.getToasts(destId);
        JsonResult success = JsonResult.success();
        success.setData(toasts);
        return success;
    }

    @GetMapping("/catalogs")
    public Object catalogs(String destId) {
        //查询目的地下的所有攻略分类,及分类下的所有攻略
        List<StrategyCatalog> list = strategyCatalogService.selectCatalogsAndStraById(destId);
        JsonResult success = JsonResult.success();
        success.setData(list);
        return success;
    }

    @GetMapping("/strategies/viewnumTop3")
    public Object viewnumTop3(String destId) {
        //查询目的地下的所有攻略,只要热度前三的
        List<Strategy> list = strategyService.selectViewnumTop3(destId);
        JsonResult success = JsonResult.success();
        success.setData(list);
        return success;
    }

    //目的地下点击量前三的游记文章
    @GetMapping("/travels/viewnumTop3")
    public Object TviewnumTop3(String destId) {
        List<Travel> list = travelService.viewnumTop3(destId);
        return JsonResult.success(list);
    }
}
